#include <jni.h>
#include <string>
#include <android/log.h>
#define TAG "HPHook--native"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)

extern "C" JNIEXPORT jstring JNICALL
Java_com_fly_nativedemo_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}


jboolean JNICALL testHook(JNIEnv *env, jobject thiz){
    LOGI("testHook start");
    return JNI_TRUE;
}


JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
{
    JNIEnv *env;
    if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
        return JNI_EVERSION;
    }

    jclass JNI = env->FindClass("com/fly/nativedemo/MainActivity");
    JNINativeMethod methods[] = {
            { "native_hook", "()Z", reinterpret_cast<void *>(&testHook) }
    };
    int numMethods = sizeof(methods) / sizeof(methods[0]);
    env->RegisterNatives(JNI, methods, numMethods);

    return JNI_VERSION_1_6;
}